﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpHomeEngine;

namespace Insteon.Requests
{
    public class EnterLinkingMode : InsteonRequest
    {
        public readonly byte Group;
        public readonly InsteonDevice Device;

        public EnterLinkingMode(Controller Controller, InsteonInterface DeviceInterface, InsteonDevice Device, byte Group)
            : base(Controller, DeviceInterface)
        {
            this.Group = Group;
            this.Device = Device;
        }

        internal override void BeginExecute()
        {
            Commands.Command Command = new Commands.Insteon.StandardCommand(Device.InsteonAddress, 0x09, Group);
            Command.InsteonRequest = this;
            InsteonInterface.QueueCommand(Command);
        }

        internal override void CommandCompleted(Commands.Command Command)
        {
            if (Command is Commands.Insteon.StandardCommand)
            {
                Commands.Command Cmd = (Commands.Command)Command;
                this.Complete(Command.isComplete, Command.isSuccessful);
            }
            else
            {
                this.Fail();
            }
        }
    }
}
